package com.farm.wlp.events;

import java.sql.SQLException;

import org.springframework.stereotype.Service;

import com.farm.authority.FarmAuthorityService;
import com.farm.core.auth.domain.LoginUser;
import com.farm.learn.utils.UserMajorLoader;
import com.farm.wuc.events.WucEventInfo;
import com.farm.wuc.events.WucEventModle;
import com.farm.wuc.events.WucEventRole;
import com.farm.wuc.events.WucEventUser;
import com.farm.wuc.events.WucEventUsers;

@Service
public class WlpAppEventHandle implements WlpEventInter {

	@Override
	public void runEvent(WucEventModle modle, WucEventInfo info, WucEventUsers users) {
		if (modle.equals(WucEventModle.CLASS_LEARN_C)) {
			// 更新专业学习记录
			updateUserMajorInfor(modle, info, users);
		}
	}

	/**
	 * 更新专业学习记录
	 * 
	 * @param modle
	 * @param info
	 * @param users
	 */
	private void updateUserMajorInfor(WucEventModle modle, WucEventInfo info, WucEventUsers users) {
		try {
			WucEventUser operatorUser = users.getUser(WucEventRole.OPRETOR);
			if (operatorUser != null) {
				LoginUser luser = FarmAuthorityService.getInstance().getUserByLoginName(operatorUser.getUserobjkey());
				if (luser != null&& info!=null && info.getObjid() != null) {
					UserMajorLoader.loadUserMajorInfo(info.getObjid(), luser.getId());
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
